<template>
  <div class="page">
    <div class="page-btn">
      <el-button @click="getDataInfo"
                 size="small"
                 type="primary">GET DATA</el-button>
    </div>
    <div class="page-test">
      <DatasetSqlModel ref="dataset-sql-builder" />
    </div>
  </div>
</template>

<script>
import DatasetSqlModel from '@/components/dataset-sql-model/index'
import { getUUID } from '@/utils'

export default {
  components: { DatasetSqlModel },
  data () {
    return {
      enterJson: {
        'aliasId': `id-${getUUID()}`.replace(/-/g, '_'),
        'datasetId': '1303758470860615682',
        'datasetName': 'Attendance Record',
        'sql': {
          'select': [
            {
              'columnName': 'Status',
              'alias': 'Status',
              'measure': 'Count'
            },
            {
              'columnName': 'User Name',
              'alias': 'User Name',
              'measure': 'Count'
            }
          ],
          'from': '1303758470860615682',
          'where': '{"condition":"and","rules":[]}',
          'groupby': [
            {
              'columnName': null
            }
          ],
          'join': [
            {
              'pKey': null,
              'fKey': null
            }
          ],
          'result': 'select Count("Status") as "Status",Count("User Name") as "User Name" from ({dataset-1303758470860615682}) as tb1  ) as id_b17db35c_9eab_48f7_8cdb_1abc2a230ca5'
        },
        'children': [
          {
            'aliasId': 'id_616ec615_e612_47f0_88d8_73acad9350d9',
            'datasetId': '1298869692912091138',
            'datasetName': 'Autotask Contacts',
            'sql': {
              'select': [
                {
                  'columnName': 'First Name',
                  'alias': 'First Name',
                  'measure': null
                },
                {
                  'columnName': 'Tenant Code',
                  'alias': 'Tenant Code',
                  'measure': null
                }
              ],
              'from': '1298869692912091138',
              'where': '{"condition":"and","rules":[]}',
              'groupby': [
                {
                  'columnName': 'First Name'
                },
                {
                  'columnName': 'Tenant Code',
                  'alias': null,
                  'measure': null
                }
              ],
              'join': [
                {
                  'pKey': 'First Name',
                  'fKey': 'User Name'
                }
              ],
              'result': 'left join (select "First Name" as "First Name","Tenant Code" as "Tenant Code" from ({dataset-1298869692912091138}) as tb1   Group By "First Name","Tenant Code") as id_616ec615_e612_47f0_88d8_73acad9350d9 on id_616ec615_e612_47f0_88d8_73acad9350d9.First Name = id_b17db35c_9eab_48f7_8cdb_1abc2a230ca5.User Name'
            },
            'children': []
          }
        ]
      }
    }
  },
  methods: {
    getDataInfo () {
      // let dataInfo = this.$refs['dataset-sql-builder'].exportDatasetSetting()
      // let SQL = this.$refs['dataset-sql-builder'].exportSQL()
    }
  }
}
</script>

<style scoped lang='scss'>
.page {
  width: 100%;
  height: calc(100vh - 50px - 38px - 30px);
  &-btn {
    height: 50px;
  }
  &-test {
    height: calc(100% - 50px);
  }
}
</style>
